﻿using System;
using ThoughtWorks.CruiseControl.Core.Tasks.Conditions;
using NUnit.Framework;

namespace ThoughtWorks.CruiseControl.UnitTests.Core.Tasks.Conditions
{
    [TestFixture]
    public class CompareValuesTaskConditionTest
    {
        //[Test]
        //[ExpectedException(typeof(ArgumentException))]
        //public void Value1NullThrowsArgumentException()
        //{
        //    CompareValuesTaskCondition condition = new CompareValuesTaskCondition();
        //    condition.Value1 = null;
        //    condition.Value2 = "testValue";
        //    condition.EvaluationType = CompareValuesTaskCondition.Evaluation.Equal;
        //    condition.IgnoreCase = true;

        //    condition.Eval(null);
        //}

        //[Test]
        //[ExpectedException(typeof(ArgumentException))]
        //public void Value2NullThrowsArgumentException()
        //{
        //    CompareValuesTaskCondition condition = new CompareValuesTaskCondition();
        //    condition.Value1 = "testValue";
        //    condition.Value2 = null;
        //    condition.EvaluationType = CompareValuesTaskCondition.Evaluation.Equal;
        //    condition.IgnoreCase = true;

        //    condition.Eval(null);
        //}

        //[Test]
        //[Description("EvaluationParsing ")]
        //[Category("Category")]
        //public void CompareValuesTaskConditionTest_EvaluationParsing_TestingEqual(
        //    [Values("equal", "Equal", "EQUAL", "eQUAL")]CompareValuesTaskCondition.Evaluation EvalString)
        //{
        //    CompareValuesTaskCondition condition = new CompareValuesTaskCondition();
        //    condition.EvaluationType = EvalString;
        //    Assert.That(condition.evaluation, Is.EqualTo("equal"), "Pasing '" + EvalString + "' Expected 'equal' but was '" + condition.evaluation + "'");
        //}

        //[Test]
        //[Description("EvaluationParsing ")]
        //[Category("Category")]
        //public void CompareValuesTaskConditionTest_EvaluationParsing_TestingNotEqual(
        //    [Values("notequal", "notEqual", "NOTEQUAL", "nOTeQUAL")]string EvalString)
        //{
        //    compareValuesTaskCondition condition = new compareValuesTaskCondition();
        //    condition.evaluation = EvalString;
        //    Assert.That(condition.evaluation, Is.EqualTo("notEqual"), "Pasing '" + EvalString + "' Expected 'notEqual' but was '" + condition.evaluation + "'");
        //}


        //[Test]
        //[Description("Evaluations Exception")]
        //[Category("Category")]
        //[ExpectedException(typeof(ArgumentException))]
        //public void CompareValuesTaskConditionTest_Evaluations_Exception()
        //{
        //    CompareValuesTaskCondition condition = new CompareValuesTaskCondition();
        //    condition.Value1 = "testValue";
        //    condition.Value2 = "testValue";
        //    condition.EvaluationType = "test";
        //    condition.IgnoreCase = true;

        //    condition.Eval(null);
        //}


        [Test]
        public void BulkTest_IgnoreCaseTest()
        {
            string[] values = new string[] {"Value1","value1","","1234","!\"#¤%&"};
            foreach (string value1 in values)
                foreach (string value2 in values)
                {
                    executeTest(value1, value2, true, string.Equals(value1, value2, StringComparison.InvariantCultureIgnoreCase));
                    executeTest(value1, value2, false, string.Equals(value1, value2, StringComparison.InvariantCulture));
                }
        }

        private void executeTest(string value1, string value2, bool ignoreCase, bool expectedValue)
        {
            CompareValuesTaskCondition condition = new CompareValuesTaskCondition();
            condition.Value1 = value1;
            condition.Value2 = value2;
            condition.EvaluationType = CompareValuesTaskCondition.Evaluation.Equal;
            condition.IgnoreCase = ignoreCase;

            string message = string.Format("comparing : '{0}' '{3}' '{1}' ('{4}') and expected '{2}'", value1, value2, expectedValue, "equal", ignoreCase ? "ignore Case" : "case sensitive");
            Assert.That(condition.Eval(null),  Is.EqualTo(expectedValue), message);
            
            condition.EvaluationType =  CompareValuesTaskCondition.Evaluation.NotEqual;
            string message2 = string.Format("comparing : '{0}' '{3}' '{1}' ('{4}') and expected '{2}'", value1, value2, expectedValue, "not equal", ignoreCase ? "ignore Case" : "case sensitive");
            Assert.That(condition.Eval(null),Is.Not.EqualTo(expectedValue),message2);
        }
    }
}
